import { ZFormItemSchema } from "@/components/Form/typings";
import {
  enumRender,
  secondsTimestampRender,
} from "@/components/Table/helpers/renders";
import { ZTableColumn } from "@/components/Table/typings";
import { hash2Options } from "@/utils";
import { NButton, NSpace } from "naive-ui";
import { Ref, ref } from "vue";
import { EvaluationStatus } from "../helpers";

export const getColumns = (): ZTableColumn[] => [
  {
    title: "评估任务ID",
    key: "id",
  },
  {
    title: "评估词",
    key: "word",
  },
  {
    title: "评估场景",
    key: "evaluation_config_id",
    filterMultiple: true,
    filterOptions: hash2Options({ 15: "15", 12: "12" }),
    filter: "default",
  },
  {
    title: "状态",
    key: "status",
    render: enumRender(EvaluationStatus),
    filterMultiple: false,
    filterOptions: hash2Options(EvaluationStatus),
    filter: "default",
  },
  {
    title: "命中率",
    key: "hit_rate",
  },
  {
    title: "误中率",
    key: "error_rate",
  },
  {
    title: "更新人",
    key: "updater",
  },
  {
    title: "更新时间",
    key: "update_time",
    render: secondsTimestampRender,
  },
];

export const getSearchSchemas = (): ZFormItemSchema[] => [
  {
    label: "评估任务ID",
    path: "id",
    span: 16,
  },
];

export const useActions = (modal: Ref) => {
  const resultData = ref({});

  function genActions() {
    return {
      fixed: "right",
      width: "280px",
      render({ rowData }: any) {
        return (
          <NSpace>
            <NButton
              quaternary
              type="primary"
              onClick={async () => {
                resultData.value = JSON.parse(rowData["hit_cases"]);
                modal.value.open();
              }}
            >
              评估结果
            </NButton>
            <NButton quaternary type="primary">
              添加
            </NButton>
            <NButton quaternary type="primary">
              更多
            </NButton>
          </NSpace>
        );
      },
    } as any;
  }

  return { resultData, genActions };
};
